package com.herohead.redis;

import java.util.List;

import redis.clients.jedis.Jedis;

public class ReadLog {

	String redisHost = "";
	String key = "t:log:message";
	int rows = 100;

	public ReadLog(){

	}
	public ReadLog(String redisServer){
		this(redisServer, "t:log:message");
	}
	public ReadLog(String redisServer, String key) {
		this(redisServer,key,100);
	}

	public ReadLog(String redisServer, String key, int rows) {
		this.redisHost = redisServer;
		this.key = key;
		this.rows = rows;
	}
	public String getKey() {
		return key;
	}
	public List<String> getLog() {

		if (redisHost.equals("")) {
			GetRedisServer getredis = new GetRedisServer();
			redisHost = getredis.getRedisHost();
		}
		Jedis jd = new Jedis(redisHost);
		List<String> log = jd.lrange(key, 0, rows);
		jd.close();
		return log;

	}
	public String getRedisHost() {
		return redisHost;
	}
	public int getRows() {
		return rows;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public void setRedisHost(String redisHost) {
		this.redisHost = redisHost;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

}
